Function.prototype.myCall = function (context = window, ...args) {
    if (Function.prototype instanceof this) { // 注意
        return new Error("不能是自己")
    }
    let x = Symbol();
    context[x] = this;
    let res = context[x](...args)
    delete context[x]
    return res;
}

Function.prototype.myApply = function (context = window, args) {
    if (Function.prototype instanceof this) { // 注意
        return new Error("不能是自己")
    }
    let res;
    let x = Symbol();
    context[x] = this;
    if (!Array.isArray(args)) {
        res = context[x]()
    } else {
        res = context[x](args)
    }
    delete context[x]
    return res;
}

Function.prototype.myBind = function (context = window, args) {
    return function (...args) {
        let res;
        let x = Symbol();
        context[x] = this;
        res = context[x](...args)
        delete context[x]
        return res;
    }
}

function curry(fn) {
    return function curryFn(...args) {
        if (fn.length == args.length) {
            fn(...args)
        } else {
            return function () { // 注意// 注意 包裹函数
                return curryFn(...args.concat(Array.from(arguments)))  // 注意// 注意
            }
        }
    }
}

function compose(...args) {
    return function (value) {
        return args.reduce((pre, next) => {
            next(pre)
        }, value)
    }

}

// compose(f1 ,f2) f2(f1())


// debounce

function debounce(fn, time) {
    let timer = null
    return function (...args) {
        clearInterval(timer)
        // 注意 没有判断
        timer = setInterval(() => {
            fn.call(this, ...args)
        }, time)
    }
}

// trottle

function trottle(fn, time) {
    let timer = null
    return function (params) {
        if (!timer) {
            timer = setInterval(() => {
                fn.call(this, ...args)
                timer = null
            }, time);
        }
    }
}